package com.vaadin.thomas.contenttool.ui;

import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.thomas.contenttool.data.Tag;

public class TagContainer extends IndexedContainer {

	private static final long serialVersionUID = -5124767276686442013L;

	public static final String CAPTION_PROPID = "caption";

	public TagContainer() {

		addContainerProperty(CAPTION_PROPID, String.class, "");

		for (Tag t : AdminMainLayout.ct().getModel().getTags()) {
			Item i = addItem(t);
			i.getItemProperty(CAPTION_PROPID).setValue(t.getValue());
		}
	}

	@Override
	public Item addItem(Object o) {
		Tag t;
		Item i;
		if (o instanceof Tag) {
			t = (Tag) o;
			i = super.addItem(o);
		} else {
			t = AdminMainLayout.ct().getModel().getTag((String) o);
			i = super.addItem(t);
		}
		i.getItemProperty(CAPTION_PROPID).setValue(t.getValue());
		return i;
	}

}
